package cn.xiaobai.utils;

import cn.xiaobai.utils.module.UUID;

/**
 * @author yangdaji
 * @version 1.0
 * @Description: uuid8位
 * @date 22-2-25 下午 10:49
 */
public class UuidUtils {


    /**
     * 简化字符串
     */
    private static String[] NUMBER_LETTER_SIMPLIFY = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
            .split("");


    /**
     * 生成随机uuid,简化横线
     *
     * @return
     */
    public static String getUuid() {
        return UUID.randomUUID().toString(true);
    }


    /**
     * 生成 8位不重复id,性能优于32位id
     *
     * @return
     */
    public static String getShortUuid() {
        StringBuilder stringBuffer = new StringBuilder();
        String uuid = getUuid();
        for (int i = 0; i < 8; i++) {
            String substring = uuid.substring(i * 4, i * 4 + 4);
            int x = Integer.parseInt(substring, 16);
            stringBuffer.append(NUMBER_LETTER_SIMPLIFY[x % 0x3E]);
        }
        return stringBuffer.toString();
    }


}